﻿using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;
using SBlogCore.Common.App.Manager;

namespace SBlogCore.EventBus.CrossProcessEventBus
{
    public static class RabbitMqExtenions
    {
        public static IApplicationBuilder UseEventBus(this IApplicationBuilder builder)
        {
            string enableEventBus = AppSetting.ReadAppSettings("EventBus:Enable");
            if (string.IsNullOrWhiteSpace(enableEventBus) || !bool.Parse(enableEventBus)) return builder;
            //获取EventBus实例，立即加载
            var eventBus = builder.ApplicationServices.GetService<IEventBus>();
            if (eventBus == null)
            {
                throw new ApplicationException("找不到IEventBus实例");
            }
            return builder;
        }
    }
}
